﻿using System;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
namespace MakeIT_Bill_Maker.Database
{
    class DatabaseConnection
    {
        public static OleDbConnection conn;
        public static OleDbDataAdapter da;

        public DatabaseConnection()
        {
            if (conn == null)
            {
                conn = new
                    OleDbConnection();
                // TODO: Modify the connection string and include any
                // additional required properties for your database.
                string filename = Properties.Settings.Default.MakeITConnectionString;

                conn.ConnectionString = filename;
                try
                {
                    conn.Open();
                    // Insert code to process data.
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to connect to data source");
                }
            }
           
        }

        public Boolean add(string sql)
        {
            OleDbCommand command = new OleDbCommand(sql, conn);
            command.ExecuteNonQuery();
            return true;

        }

        public DataSet Show(string sql)
        {
            OleDbCommand sc = new OleDbCommand(sql, conn);
            da = new OleDbDataAdapter(sc);
            DataSet ds = new DataSet("TitlesDS");
            da.Fill(ds);
            return ds;

        }

        public Boolean edit(string sql)
        {
            OleDbCommand command = new OleDbCommand(sql, conn);
            command.ExecuteNonQuery();
            return true;

        }

        public Boolean delete(string sql)
        {
            OleDbCommand command = new OleDbCommand(sql, conn);
            command.ExecuteNonQuery();
            return true;

        }
    }
}
